package com.jrh.dal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jrh.domain.entity.Feature;

public class FeatureDao extends BaseDao<Feature> {

    public FeatureDao(){
        this.namespace = "jrh.single.feature";
    }

    @SuppressWarnings("unchecked")
    public List<Feature> listFeatureByCondition(String categoryId, Integer start, Integer pageSize) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("start", start);
        params.put("pageSize", pageSize);
        params.put("categoryId", categoryId);
        List<Feature> features = (List<Feature>) sqlMapClientTemplate.queryForList(namespace
                                                                                   + ".listFeatureByCondition", params);
        return features;
    }

    public int countFeatureByCondition(String categoryId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("categoryId", categoryId);
        int count = (Integer) sqlMapClientTemplate.queryForObject(namespace + ".listFeatureByCondition_count", params);
        return count;
    }

    @SuppressWarnings("unchecked")
    public List<Feature> listFeatureDetailByCategory(String categoryId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("categoryId", categoryId);
        List<Feature> features = (List<Feature>) sqlMapClientTemplate.queryForList(namespace
                                                                                           + ".listFeatureDetailByCategory",
                                                                                   params);
        return features;
    }

    @SuppressWarnings("unchecked")
    public List<Feature> listFeatureDetailByProduct(Long pId) {
        List<Feature> features = (List<Feature>) sqlMapClientTemplate.queryForList(namespace
                                                                                   + ".listFeatureDetailByProduct", pId);
        return features;
    }
}
